Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lambda_manager: revamp function parsing error handling #8406

Merged
merged 2 commits into from
Sep 6, 2024

Conversation

SpecLad
Copy link
Contributor

@SpecLad SpecLad commented Sep 5, 2024

Motivation and context

This has several goals:

  • Remove LambdaType.UNKNOWN. Functions with this non-type are useless and should not be presented to the user.

  • Don't return 404 from the list endpoint if one function cannot be loaded. This prevents one bad function from essentially disabling the entire serverless function feature. Instead, log the error and ignore the function.

  • Don't return 404 from other endpoints either when the problem is a bad function. This is not a client problem. Raise an exception and let Django log it and return a 500.

  • Remove HTTP codes from LambdaFunction, to improve separation of concerns.

How has this been tested?

Manual testing.

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • [ ] I have updated the documentation accordingly
  • [ ] I have added tests to cover my changes
  • [ ] I have linked related issues (see GitHub docs)
  • [ ] I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features

    • Improved error handling for lambda function endpoints, providing clearer feedback on invalid metadata.
    • Introduced validation for lambda function types, ensuring only valid functions are displayed in the output.
  • Bug Fixes

    • Resolved an issue where a single lambda function with invalid metadata would disrupt the entire function listing process.
  • Documentation

    • Updated changelog to reflect the changes in error handling and validation processes.

Copy link
Contributor

coderabbitai bot commented Sep 5, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update enhances the error handling for lambda function endpoints by changing the response for invalid metadata from a 404 to a 500 error. It introduces a new validation step for lambda function types and implements a new exception class, InvalidFunctionMetadataError, for clearer error reporting. The list method is modified to yield instances instead of returning a list, improving memory efficiency.

Changes

Files Change Summary
cvat/apps/lambda_manager/views.py Removed UNKNOWN member from LambdaType enum; added InvalidFunctionMetadataError class; modified list method to yield instances; updated error handling in LambdaFunction constructor and parse_attributes method.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LambdaFunction
    participant ServerLogManager

    User->>LambdaFunction: Request list of functions
    LambdaFunction->>LambdaFunction: Validate function metadata
    alt Invalid metadata
        LambdaFunction->>ServerLogManager: Log error
        LambdaFunction-->>User: Return 500 error
    else Valid metadata
        LambdaFunction-->>User: Return list of functions
    end
Loading

Poem

🐰 In the meadow where functions play,
A change has come to brighten the day.
Errors once hidden, now clear as the sky,
With logs that whisper, "Oh my, oh my!"
So hop along, let the good times flow,
For lambdas are spry, and the bugs are low! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

This has several goals:

* Remove `LambdaType.UNKNOWN`. Functions with this non-type are useless
  and should not be presented to the user.

* Don't return 404 from the list endpoint if one function cannot be loaded.
  This prevents one bad function from essentially disabling the entire
  serverless function feature. Instead, log the error and ignore the
  function.

* Don't return 404 from other endpoints either when the problem is a bad
  function. This is not a client problem. Raise an exception and let Django
  log it and return a 500.

* Remove HTTP codes from `LambdaFunction`, to improve separation of
  concerns.
@SpecLad SpecLad marked this pull request as ready for review September 5, 2024 17:34
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 510fd98 and 746c49a.

Files selected for processing (2)
  • changelog.d/20240905_201903_roman_lambda_error_handling.md (1 hunks)
  • cvat/apps/lambda_manager/views.py (7 hunks)
Additional comments not posted (8)
changelog.d/20240905_201903_roman_lambda_error_handling.md (3)

3-5: Changelog entry is clear and accurate.

This entry correctly summarizes the changes made to the error handling in lambda function endpoints, aligning with the PR objectives.


7-9: Changelog entry is clear and accurate.

This entry effectively communicates the removal of LambdaType.UNKNOWN and its implications for the list endpoint, which is a key objective of the PR.


13-15: Changelog entry is clear and accurate.

This entry correctly describes the fix to prevent a single invalid lambda function from disrupting the entire function listing, aligning with the PR's error handling improvements.

cvat/apps/lambda_manager/views.py (5)

51-57: Confirmed Removal of LambdaType.UNKNOWN.

The enumeration LambdaType no longer includes UNKNOWN, which aligns with the PR objectives to improve clarity and prevent the use of undefined lambda function types.


97-101: Improved Error Handling in list Method.

The modification to yield instances instead of returning a list enhances memory efficiency. The error handling by logging and continuing processing when encountering InvalidFunctionMetadataError is a robust approach, ensuring that one faulty function does not affect the availability of others.


138-140: Introduction of InvalidFunctionMetadataError.

The new exception class InvalidFunctionMetadataError is a welcome addition for clearer and more specific error reporting when handling lambda function metadata issues.


Line range hint 156-202: Enhanced Error Handling in LambdaFunction.

The modifications in the constructor and parse_labels method of the LambdaFunction class to use InvalidFunctionMetadataError enhance the clarity and consistency of error handling. This change ensures that errors are more descriptive and aligned with the types of issues encountered during lambda function instantiation.


138-140: Review of LambdaQueue.

The LambdaQueue class appears unchanged in this PR. It's important to ensure that its functionality aligns with the overall changes in error handling and lambda function management. No issues are found with the current implementation in the context of this PR.

Copy link

sonarcloud bot commented Sep 6, 2024

@SpecLad SpecLad merged commit c8f57e3 into cvat-ai:develop Sep 6, 2024
33 checks passed
@SpecLad SpecLad deleted the lambda-error-handling branch September 6, 2024 11:31
This was referenced Sep 9, 2024
bschultz96 pushed a commit to bschultz96/cvat that referenced this pull request Sep 12, 2024
This has several goals:

* Remove `LambdaType.UNKNOWN`. Functions with this non-type are useless
  and should not be presented to the user.

* Don't return 404 from the list endpoint if one function cannot be
  loaded. This prevents one bad function from essentially disabling the
  entire serverless function feature. Instead, log the error and ignore
  the function.

* Don't return 404 from other endpoints either when the problem is a bad
  function. This is not a client problem. Raise an exception and let
  Django log it and return a 500.

* Remove HTTP codes from `LambdaFunction`, to improve separation of
  concerns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant